//package com.smfx.yxt.controller.teacher;
//
//import com.smfx.yxt.common.RspResult;
//import com.smfx.yxt.common.enums.Status;
//import com.smfx.yxt.controller.BaseController;
//import com.smfx.yxt.model.TeacherInfo;
//import com.smfx.yxt.model.TeacherWorkSign;
//import com.smfx.yxt.reqVo.TeacherWorkSignReqVO;
//import com.smfx.yxt.service.ITeacherService;
//import com.smfx.yxt.service.ITeacherWorkSignService;
//import com.smfx.yxt.utils.DateUtil;
//import com.smfx.yxt.utils.RequestUtil;
//import com.smfx.yxt.utils.StringUtil;
//import java.net.InetAddress;
//import java.net.UnknownHostException;
//import java.util.Calendar;
//import java.util.Date;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpSession;
//import org.apache.commons.lang.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.ui.Model;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
//
//@RequestMapping({"common/work"})
//@Controller
//public class TeacherWorkController_back extends BaseController
//{
//  private Logger logger = LoggerFactory.getLogger(TeacherWorkController_back.class);
//
//  private static String TEACHER_AM_START_DATE = " 6:00";
//  private static String TEACHER_AM_END_DATE = " 8:00";
//
//  private static String TEACHER_PM_START_DATE = " 13:50";
//  private static String TEACHER_PM_END_DATE = " 15:00";
//
//  @Autowired
//  private ITeacherWorkSignService teacherWorkSignService;
//
//  @Autowired
//  private ITeacherService teacherService;
//
//  @RequestMapping({"cardSign"})
//  public String cardSign(Model model) { String openid = this.request.getParameter("openid");
//    if (StringUtils.isNotBlank(openid)) {
//      TeacherInfo teacher = this.teacherService.selectByOpenid(openid);
//      this.session.setAttribute("teacherId", teacher.getId());
//      this.session.setAttribute("teacherName", teacher.getName());
//      return "redirect:/common/work/cardSign";
//    }
//    model.addAttribute("ip", RequestUtil.getIpAddr(this.request));
//    model.addAttribute("teacherName", this.session.getAttribute("teacherName").toString());
//    return "work/cardSign"; 
//  } 
//  
//  @RequestMapping({"today"})
//  @ResponseBody
//  Object todaySign(Integer teacherId) { 
//	TeacherWorkSignReqVO vo = new TeacherWorkSignReqVO();
//    vo.setTeacherId(Integer.valueOf(this.session.getAttribute("teacherId").toString()));
//    return this.teacherWorkSignService.selectListForToday(vo); 
//  } 
//  
//  @RequestMapping({"cardSign/submit"})
//  @ResponseBody
//  Object cardSignSubmit(String ip) { try { Integer teacherId = Integer.valueOf(this.session.getAttribute("teacherId").toString());
//      Date signTime = Calendar.getInstance().getTime();
//      Long currTime = Long.valueOf(Calendar.getInstance().getTimeInMillis());
//      String currDate = DateUtil.dateToStr(new Date(), 
//        "yyyy-MM-dd");
//      Long startDate = null;
//      Long endDate = null;
//      int signType = 0;
//      if (DateUtil.isAmOrPm() == 0) signType = 1; else
//        signType = 2;
//      if (signType == 1) {
//        startDate = 
//          Long.valueOf(DateUtil.strToDate(currDate + TEACHER_AM_START_DATE, 
//          "yyyy-MM-dd HH:mm").getTime());
//        endDate = 
//          Long.valueOf(DateUtil.strToDate(currDate + TEACHER_AM_END_DATE, 
//          "yyyy-MM-dd HH:mm").getTime());
//      } else {
//        startDate = 
//          Long.valueOf(DateUtil.strToDate(currDate + TEACHER_PM_START_DATE, 
//          "yyyy-MM-dd HH:mm").getTime());
//        endDate = 
//          Long.valueOf(DateUtil.strToDate(currDate + TEACHER_PM_END_DATE, 
//          "yyyy-MM-dd HH:mm").getTime());
//      }
//      if ((currTime.longValue() >= startDate.longValue()) && (currTime.longValue() <= endDate.longValue())) {
//        TeacherWorkSignReqVO record = new TeacherWorkSignReqVO();
//        record.setTeacherId(teacherId);
//        record.setSignType(Integer.valueOf(signType));
//        int count = this.teacherWorkSignService.selectCountForToday(record);
//        if (count > 0) {
//          return new RspResult(Status.CARD_SIGN_SUCESS);
//        }
//        TeacherWorkSign cardSign = new TeacherWorkSign();
//        cardSign.setSignType(Integer.valueOf(signType));
//        cardSign.setRemark(ip);
//        cardSign.setTeacherId(teacherId);
//        cardSign.setSignTime(signTime);
//        this.teacherWorkSignService.insertSelective(cardSign);
//        return new RspResult(Status.SUCCESS);
//      }
//      return new RspResult(Status.CARD_SIGN_TIMEOUT);
//    } catch (Exception e) {
//      this.logger.error("--cardSignSubmit error={}", e);
//    }
//    return new RspResult(Status.FAIL); 
//  }
//  
//	@RequestMapping("signTotal")
//	public String signTotal(Model model) {
//		return "work/signTotal";
//	}
//	
//	@RequestMapping("weekTotal")
//	@ResponseBody Object weekTotal(Integer diffDay) {
//		TeacherWorkSignReqVO vo = new TeacherWorkSignReqVO();
//		String teacherId = session.getAttribute("teacherId").toString();
//		vo.setTeacherId(Integer.valueOf(teacherId));
//		vo.setDiffDay(diffDay);
//		return teacherWorkSignService.selectListForTotal(vo);
//	}
//
//  private String getIp() {
//    String ip = null;
//    try
//    {
//      InetAddress inet = null;
//      inet = InetAddress.getLocalHost();
//      ip = inet.getHostAddress();
//    } catch (UnknownHostException e) {
//      e.printStackTrace();
//    }
//    return StringUtil.nullToEmpty(ip);
//  }
//}